module hip_wrapper
    use, intrinsic :: iso_c_binding, only: c_int, c_size_t, c_ptr
    
    implicit none
    
    ! 声明HIP错误码
    integer(c_int), parameter :: hipSuccess = 0
    
    ! 声明内存拷贝类型
    integer(c_int), parameter :: hipMemcpyHostToDevice = 1
    integer(c_int), parameter :: hipMemcpyDeviceToHost = 2
    
    interface      
        function hipMalloc(devPtr, size) bind(C, name="hipMalloc")
            use iso_c_binding
            integer(c_int) :: hipMalloc
            type(c_ptr), intent(out) :: devPtr
            integer(c_size_t), value, intent(in) :: size
        end function
        
        function hipFree(devPtr) bind(C, name="hipFree")
            use iso_c_binding
            integer(c_int) :: hipFree
            type(c_ptr), value, intent(in) :: devPtr
        end function
        
        function hipMemcpyAsync(dst, src, size, kind, stream) bind(C, name="hipMemcpyAsync")
            use iso_c_binding
            integer(c_int) :: hipMemcpyAsync
            type(c_ptr), value, intent(in) :: dst
            type(c_ptr), value, intent(in) :: src
            integer(c_size_t), value, intent(in) :: size
            integer(c_int), value, intent(in) :: kind
            integer(c_size_t), value, intent(in) :: stream  ! 改为 c_size_t
        end function
        
        function hipStreamCreate(stream) bind(C, name="hipStreamCreate")
            use iso_c_binding
            integer(c_int) :: hipStreamCreate
            integer(c_size_t), intent(out) :: stream  ! 改为 c_size_t
        end function
        
        function hipStreamSynchronize(stream) bind(C, name="hipStreamSynchronize")
            use iso_c_binding
            integer(c_int) :: hipStreamSynchronize
            integer(c_size_t), value, intent(in) :: stream  ! 改为 c_size_t
        end function
        
        function hipStreamDestroy(stream) bind(C, name="hipStreamDestroy")
            use iso_c_binding
            integer(c_int) :: hipStreamDestroy
            integer(c_size_t), value, intent(in) :: stream  ! 改为 c_size_t
        end function
        
        function hipInit(flags) bind(C, name="hipInit")
            use iso_c_binding
            integer(c_int) :: hipInit
            integer(c_int), value, intent(in) :: flags
        end function
    end interface
end module hip_wrapper